function loadScript(url) {
    return new Promise((resolve, reject) => {
        let script = document.createElement("script");

        script.src = url;
        script.onload = () => {
            console.info("load:", url);
            resolve();
        };
        script.onerror = (err) => reject(err);
        document.body.appendChild(script);
    });
}
function loadCss(url) {
    return new Promise((resolve, reject) => {
        let link = document.createElement("link");
        link.rel = "stylesheet";
        link.type = "text/css";
        link.href = url;
        document.body.appendChild(link);
        link.onload = () => {
            console.info("load:", url);
            resolve();
        };
        link.onerror = (err) => reject(err);
    });
}
export default function load(url, options = {}) {
    const type = options.type || "script"; // script
    switch (url.replace(/.*\.([^\.]+)$/g, "$1")) {
        case "js":
            switch (type) {
                case "script":
                    return loadScript(url);
                case "module":
                    return import(url);
            }
            break;
        case "css":
            return loadCss(url);
        default:
            return loadScript(url);
    }
}
